<template>
    <div class="center_div">
        <el-table :data="Department" v-loading="tableLoading" element-loading-text="Loading">
            <el-table-column prop="departmentid" label="部门id" min-width="90"></el-table-column>
            <el-table-column prop="departmentname" label="部门" min-width="90"></el-table-column>
            <el-table-column label="操作" min-width="120" align="center">
                <template slot-scope="scope">
                    <el-button type="success" @click="grantTime(scope.row.departmentid)" >发放抽奖次数</el-button>
                </template>
            </el-table-column>
        </el-table>
    </div>
</template>

<script>
    export default {
        data() {
            return {
                Department: [
                    {departmentid: '测试1',departmentname: '组织部'},
                    {departmentid: '测试2',departmentname: '体育部'},
                    {departmentid: '测试3',departmentname: '爱情部'},
                    {departmentid: '测试4',departmentname: '秘书部'},
                    {departmentid: '测试5',departmentname: '哈哈部'}
                ],
                tableLoading: false
            }
        },
        created() {
            this.fetchDepart()
        },
        methods: {
            async fetchDepart(){
                this.tableLoading = true
                let {code ,data ,msg} = await this.$post('/register')
                if(code === 200) {
                    this.Department = data
                }else {
                    this.$message.error(msg)
                }
                this.tableLoading = false
            },
            async grantTime(id){
                console.log(id)
                let {code ,data ,msg} = await this.$post('/managerboss/updateawardtime',{
                    data: {id:id}
                })
                if(code === 200) {
                    console.log(data)
                    this.$message({
                        message: '奖品次数发放成功',
                        type: 'success'
                    })
                }else {
                    this.$message.error(msg)
                }
            }
        }

    }
</script>

<style>
    .center_div{
        width: 90%;
        margin:0 auto;
        margin-bottom: 50px;
    }
</style>